package com.hb.trade.server.center.au.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hb.core.pojo.center.au.dto.OrgDTO;
import com.hb.core.pojo.center.au.entity.OrgSupply;
import com.hb.core.pojo.center.au.entity.User;
import com.hb.core.pojo.center.au.mapper.OrgSupplyMapper;
import com.hb.core.pojo.center.au.mapper.UserMapper;
import com.hb.trade.server.center.au.service.OrgSupplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 招标人关联供应商表(供应商库) 服务实现类
 * </p>
 *
 * @author zhaojk
 * @since 2022-01-26
 */
@Service
public class OrgSupplyServiceImpl extends ServiceImpl<OrgSupplyMapper, OrgSupply> implements OrgSupplyService {

    @Resource
    private UserMapper userMapper;

    /**
     * 查询供应商库
     *
     * @author tian
     * @date 2022-5-6 17:44
     * @param org
     * @return java.util.List<com.hb.core.pojo.center.au.dto.OrgDTO>
     */
    @Override
    public Page<OrgDTO> pageSupply(OrgDTO org) {
        Page<OrgDTO> orgDTOPage = baseMapper.pageSupply(org.pages(), org);
        if (null != orgDTOPage && CollUtil.isNotEmpty(orgDTOPage.getRecords())) {
            for (OrgDTO orgDTO : orgDTOPage.getRecords()) {
                if(null != orgDTO){
                    // 查询当前企业下首个用户
                    User user = userMapper.selectFirstUserByOrgId(orgDTO.getId());
                    if (null != user) {
                        orgDTO.setContactName(user.getFullName());
                        orgDTO.setContactPhone(user.getPhone());
                    }
                }
            }
        }
        return orgDTOPage;
    }
}
